package com.ruoyi.web.controller.share;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.VerifyCodeUtils;
import com.ruoyi.share.domain.ShareUsersLogin;
import com.ruoyi.share.service.IShareUsersLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user")
public class ShareUserController extends BaseController {
    @Autowired
    private IShareUsersLoginService shareUsersLoginService;

    /**
     * 注册用户登录
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ShareUsersLogin shareUsersLogin)
    {
        return new AjaxResult(500,"注册用户，请联系后台管理员",null);
    }

    /**
     * 修改登录用户
     */
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ShareUsersLogin shareUsersLogin)
    {
        return toAjax(shareUsersLoginService.updateShareUsersLogin(shareUsersLogin));
    }

    /**
     * 登录
     * @param shareUsersLogin
     * @return
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody ShareUsersLogin shareUsersLogin){
        return shareUsersLoginService.selectShareUsersLoginByPhoneAndPass(shareUsersLogin.getPhoneNumber(),shareUsersLogin.getPassword());
    }

    /**
     * 随机产生四位验证码
     * @return
     */
    @PostMapping("/verify")
    public AjaxResult verifyCode(){
        String verification = VerifyCodeUtils.generateVerifyCode(4);
        return new AjaxResult(200,verification,null);
    }

}
